package me.azthink.myblog.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import me.azthink.myblog.domain.Nav;
import me.azthink.myblog.utils.DBUtils;

public class NavDAO {
	public List<Nav> findAll() throws SQLException{

		// 1.获取链接
		Connection conn = DBUtils.getConnection();

		// 2.拼接SQL
		String sql = "select * from nav";

		// 3.获取执行者，放松SQL
		PreparedStatement st = conn.prepareStatement(sql);
		//st.setInt(1, id);
		ResultSet rs = st.executeQuery();

		// 4.处理结果
		List<Nav> navList = new ArrayList<>();
		while (rs.next()) {
			Nav nav = new Nav();
			nav.setId(rs.getInt("id"));
			nav.setTitle(rs.getString("title"));
			nav.setInside(rs.getBoolean("inside"));
			nav.setBlank(rs.getBoolean("blank"));
			nav.setUrl(rs.getString("url"));
			nav.setSort(rs.getInt("sort"));
			nav.setStatus(rs.getBoolean("status"));
			navList.add(nav);
		}

		// 5.关闭资源
		DBUtils.closeResource(conn, st, rs);
		return navList;
	}
}
